//表单切换
let item = document.querySelector("item");
let it = document.querySelectorAll('.item>div')

let content = document.querySelector("content");
let con = document.querySelectorAll('.box')

for (let i = 0; i < it.length; i++) {
	it[i].onclick = function () {
		for (let j = 0; j < it.length; j++) {
			it[j].className = '';
			con[j].style.display = "none";
		}
		this.className = "active";
		it[i].index = i;
		con[i].style.display = "block";
	}
}

//非空验证和存储数据
const dlun = document.querySelector('#dlun')
const dlps = document.querySelector('#dlps')
const zcun = document.querySelector('#zcun')
const zcps = document.querySelector('#zcps')
const dlbtn = document.querySelector('#dlbtn')
const zcbtn = document.querySelector('#zcbtn')



const dlunkong = () => {
	if (dlun.value == '') {
		alert('请输入账号')
	}
}
const dlpskong = () => {
	if (dlps.value == '') {
		alert('请输入密码')
	}
}
const zcunkong = () => {
	if (zcun.value == '') {
		alert('请注册账号')
	}
}
const zcpskong = () => {
	if (zcps.value == '') {
		alert('请注册密码')
	}
}
const zcunps = () => {
	let username = zcun.value
	let password = zcps.value
	let reg = /[A-Za-z0-9]{7,}/
	if (!reg.test(password)) {
		alert('密码必须是至少七位数字或者字母')
	} else {
		let zcval =[ { password:password, username:username}]
		localStorage.setItem('CCC', JSON.stringify(zcval))
		alert('注册成功，可以登录了')
	}
}
const dlunps = () => {
	let dlusername = dlun.value
	let dlpassword = dlps.value
	let ccc = localStorage.getItem('CCC')
	console.log(ccc);
	let cccc = JSON.parse(ccc)
	console.log(cccc);
	
	cccc.forEach(item => {
		if (dlpassword == item.password && dlusername == item.username) {
			location.href = "../index.html"
		} else if (dlusername != item.username) {
			alert('输入的账号错误或不存在')
		} else if (dlpassword != item.password) {
			alert('输入的密码错误')
		}
	});
}


dlbtn.onclick = function () {
	dlunkong()
	dlpskong()
	dlunps()
}
zcbtn.onclick = function () {
	zcunkong()
	zcpskong()
	zcunps()
}

//弹出隐藏窗口
let xybtn = document.querySelector('.xybtn')
let btn = document.querySelector('.btn')
let bigbox = document.querySelector('.bigbox')

xybtn.onclick = function () {
	bigbox.style.display = "block"
	btn.onclick = function () {
		bigbox.style.display = "none"
	}
}